﻿using System.Windows;
using System.Windows.Controls;

using Silversocial.Client.Modules;
using Silverstone.DI;

namespace Silversocial.Client.Views
{
    public partial class Shell : IAppShell
    {
        /// <summary>
        ///     Identifies the <see cref="User"/> dependency property
        /// </summary>
        private static readonly DependencyProperty UserProperty = 
            DependencyProperty.Register("User", typeof(User), typeof(Shell), new PropertyMetadata(HandleUserPropertyChanged));

        /// <summary>
        ///     Initialises a new instance of the <see cref="Shell"/> class
        /// </summary>
        public Shell(IContainer container) : base(container)
        {
            InitializeComponent();
        }

        /// <summary>
        ///     Provides the main panel as a container to the shell base
        /// </summary>
        protected override Panel MainContainer
        {
            get { return this.pageContainer; }
        }

        /// <summary>
        ///     Gets or sets the current user
        /// </summary>
        public User User
        {
            get { return (User) GetValue(UserProperty); }
            set { SetValue(UserProperty, value); }
        }

        private static void HandleUserPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Shell shell = (Shell) d;
            User user = (User) e.NewValue;

            shell.userInfoLabel.Text = 
                user == null ? "You are not logged in" : "You are logged in as " + user.Username;
        }
    }
}
